import storageApi from '../../../core/storage/storage';

function deviceMonthController($rootScope, $scope, homeStatsService) {
  'ngInject';

  /*eslint-disable */
  var date = new Date();
  this.month = date.getMonth() + 1;

  // 设备进出场本月统计
  this.statsMonthDevice = () => {
    homeStatsService
      .queryDeviceInOut({ orgId: $rootScope.orgId || storageApi.get('orgId') })
      .then((res) => {
        if (res.success) {
          this.deviceNum = res.rows;
          if (this.deviceNum && this.deviceNum.length > 0) {
            this.deviceNum.forEach((item) => {
              if (parseInt(item.month) === this.month) {
                this.enterNum = item.enterNum;
                this.leaveNum = Math.abs(item.leaveNum);
                this.inNum = item.inNum;
              }
            });
          }
        }
      });
  };

  this.statsMonthDevice();
}

export default deviceMonthController;
